//
//  LGForumHelpCenterViewController.m
//  ligenyun
//
//  Created by Mac on 2018/4/10.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGForumHelpCenterViewController.h"
#import "LGForumHomeTableViewCell.h"
@interface LGForumHelpCenterViewController ()
@property(nonatomic, strong) UISegmentedControl     *segement;
@end

@implementation LGForumHelpCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"帮助中心";
    [self configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = [UIColor whiteColor];
#pragma mark --头部灰色View
    UIView * grawHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 10, UIScreenWidth, 105)];
    grawHeader.backgroundColor = TM_backgroundColor;
    [header addSubview:grawHeader];
    
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 85, 85)];
    bannerImageView.image = [UIImage imageNamed:@"1"];
    [grawHeader addSubview:bannerImageView];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(bannerImageView.right + 10, bannerImageView.top, 130, 20)
                                                     text:@"帮助中心"
                                                textColor:FirstTextColor
                                                     font:16
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [grawHeader addSubview:titleLable];
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(bannerImageView.right + 10, titleLable.bottom, 200, 40)
                                                     text:@"社区简介搭建临时大就撒来得及阿拉斯加的拉伸件大事了解到啦"
                                                textColor:SecendTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [grawHeader addSubview:desLable];
    
    STButton* goodButton = [[STButton alloc] initWithFrame:CGRectMake(titleLable.left, desLable.bottom, 80, 44)
                                                title:@"123"
                                           titleColor:SecendTextColor
                                            titleFont:14
                                         cornerRadius:0
                                      backgroundColor:nil
                                      backgroundImage:nil
                                                image:[UIImage imageNamed:@"已点赞"]];
    goodButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    goodButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [grawHeader addSubview:goodButton];
    
    
    STButton *  commentButton = [[STButton alloc] initWithFrame:CGRectMake(goodButton.right + 20, desLable.bottom, 80, 44)
                                                   title:@"13323"
                                              titleColor:SecendTextColor
                                               titleFont:14
                                            cornerRadius:0
                                         backgroundColor:nil
                                         backgroundImage:nil
                                                   image:[UIImage imageNamed:@"论坛_消息"]];
    commentButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    commentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [grawHeader addSubview:commentButton];
    
    STButton * qiandaoButton = [[STButton alloc] initWithFrame:CGRectMake(20+ titleLable.right, titleLable.right, 70, 25)
                                                         title:@"签到"
                                                    titleColor:FlatWhite
                                                     titleFont:14
                                                  cornerRadius:4
                                               backgroundColor:RGB(0xBCBCBC)
                                               backgroundImage:nil
                                                         image:nil];
    qiandaoButton.centerY = titleLable.centerY;
    qiandaoButton.userInteractionEnabled = YES;
    [qiandaoButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedQianDaoButton:sender];
    }];
    qiandaoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [grawHeader addSubview:qiandaoButton];
#pragma mark --推荐三个按钮
    STButton * hotButton1 = [self hotButtonWithTitle:@"祭祀是华夏店里的一部分，是儒家思想。。"];
    hotButton1.top = grawHeader.bottom + 10;
    [header addSubview:hotButton1];
    
    STButton * hotButton2 = [self hotButtonWithTitle:@"祭祀是华夏店里的一部分，是儒家思想。。"];
    hotButton2.top = hotButton1.bottom ;
    [header addSubview:hotButton2];
    
    STButton * hotButton3 = [self hotButtonWithTitle:@"祭祀是华夏店里的一部分，是儒家思想。。"];
    hotButton3.top = hotButton2.bottom ;
    [header addSubview:hotButton3];
#pragma mark --section顶部
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, hotButton3.bottom, UIScreenWidth, 10)];
    line.backgroundColor = self.tableView.backgroundColor;
    [header addSubview:line];
    
    UIView * sectionHeader = [TMUtils headerViewWithTitle:@"帖子"];
    sectionHeader.top = line.bottom;
    [header addSubview:sectionHeader];
    
    self.segement = [[UISegmentedControl alloc] initWithItems:@[@"最新",@"热门"]];
    self.segement.frame = CGRectMake(15, 44, 50 * 2, 30);
    self.segement.tintColor = FlatGray;
    self.segement.right = UIScreenWidth - 15;
    self.segement.centerY = sectionHeader.height / 2;
    self.segement.selectedSegmentIndex = 0;
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateSelected];
    [self.segement setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
    [self.segement addTarget:self action:@selector(onSelctedSegement:) forControlEvents:UIControlEventValueChanged];
    [sectionHeader addSubview:self.segement];
    
    
    header.height = sectionHeader.bottom;
    self.tableView.tableHeaderView = header;
}
- (STButton*)hotButtonWithTitle:(NSString*)title{
    STButton * hotButton1 = [[STButton alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)
                                                      title:title
                                                 titleColor:SecendTextColor
                                                  titleFont:14
                                               cornerRadius:0
                                            backgroundColor:[UIColor whiteColor]
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:@"论坛_顶"]];
    hotButton1.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    hotButton1.titleEdgeInsets = UIEdgeInsetsMake(0, 25, 0, 0);
    return hotButton1;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [LGForumHomeTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    LGForumHomeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[LGForumHomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [self.navigationController pushViewController:[LGForumDetailViewController new] animated:YES];
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma mark --Action Method
- (void)onSelctedQianDaoButton:(UIButton*)sender{
    
}
- (void)onSelctedSegement:(UISegmentedControl*)seg{
    
}
@end
